package cn.tradewin.advisor.pages.master;

import org.apache.tapestry5.annotations.Log;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.slf4j.Logger;

import cn.tradewin.advisor.exceptions.DBException;
import cn.tradewin.advisor.persist.model.Job;
import cn.tradewin.advisor.persist.services.JobService;

public class JobUpd {
	
	private String id;
	
	@Property
	private Job job;

	@Inject
	private JobService jobService;
	
	@Inject
	private Logger log;
	
	void onActivate(String id) throws DBException {
		this.id = id;
	}

	String onPassivate() {
		return id;
	}

	void onPrepareForRender() {
		job = jobService.findJob(id);
	}
	
	void onPrepare() {
		if (job == null) {
			job = new Job();
		}
	}

	Object onBack() {
		return JobBoard.class;
	}

	@Log
	Object onSubmit() {
		jobService.updJob(job);
		return JobBoard.class;
	}
}
